package com.njcb.game.service;

import com.njcb.ams.util.AmsAssert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author LOONG
 */
@Service
public class QuestionsCheckService {
    private static final Logger logger = LoggerFactory.getLogger(QuestionsCheckService.class);
    @Autowired
    private RestTemplate restTemplate;

    public String checkQuestion(String url, String param){
        HttpHeaders headers = new HttpHeaders();
        HttpEntity httpEntity = new HttpEntity(param, headers);
        logger.debug("\ntoken授权码换令牌URL:" + url);
        ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
        logger.debug("\ntoken授权码换令牌:" + responseEntity.getBody());
        if (HttpStatus.OK == responseEntity.getStatusCode()) {
            return responseEntity.getBody();
        } else {
            AmsAssert.fail(String.valueOf(responseEntity.getStatusCode()));
        }
        return null;
    }

}
